package com.example.password.controller;

import com.example.password.pojo.Pwd;
import com.example.password.service.PwdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Pwd")
public class PwdController {
    @Autowired
    PwdService pwdService;
    @GetMapping("/getPwdList")
    public List<Pwd> getPwdList(){
        List<Pwd> pwdList = pwdService.getPwdList();
        return pwdList;
    }

    @RequestMapping("/getPwd")
    public List<Pwd> getPwd(@RequestParam("accountName") String accountName){
        List<Pwd> pwd = pwdService.getPwd(accountName);
        return pwd;
    }

    @PostMapping("/addPwd")
    public int addPwd(@RequestBody Pwd pwd){
        int result = pwdService.addPwd(pwd);
        return result;
    }
    @PostMapping("/deletePwd")
    public int deletePwd(@RequestBody Pwd pwd){
        int result = pwdService.deletePwd(pwd);
        return result;
    }
    @RequestMapping("/deletePwdById")
    public int deletePwdById(@RequestParam("id") int id){
        int result = pwdService.deletePwdById(id);
        return result;
    }

    @PostMapping("/updatePwd")
    public Pwd updatePwd(@RequestBody Pwd pwd){
        int result = pwdService.upadtePwd(pwd);
        if (result > 0){
            return pwd;
        }else {
            return null;
        }
    }
}
